import { put, takeEvery } from 'redux-saga/effects';

const delay = (ms: number) => new Promise((res) => setTimeout(res, ms));

export enum ActionType {
    ADD_COUNT = 'ADD_COUNT',
}

export function* addCountAsync() {
    yield put({ type: 'SET_LOADING', loading: true });
    yield delay(1000);
    yield put({ type: ActionType.ADD_COUNT });
    yield put({ type: 'SET_LOADING', loading: false });
}

export function* watchAddCountAsync() {
    yield takeEvery('ADD_COUNT_ASYNC', addCountAsync);
}
